% Murder results
clear
load  murder_data


tempind = (year<2008);
L_murder = murder(tempind);

tempind = (year>1990);
murder = murder(tempind);
year = year(tempind);


num_coef = 3;

cons = ones(length(murder),1);
[temp,~,r,~,stats]= regress(murder, [cons L_murder year ]);
arvals = temp(2);
temp = sqrt(diag(inv(length(cons))*(r'*r)*inv([cons L_murder year ]'*[cons L_murder year ])));
arsevals = temp(2);

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

T = 7; beta = .95; M= 1;

R = length(arvals);
pxest = zeros(2,1);
gammamur  = zeros(R,1);
dgammamurdrho = zeros(R,1);

for i = 1:R
    pxest(2) = arvals(i);
    [gammamur(i), dgammamurdrho(i)] = gammafunc_se(T,beta,M,pxest);
end

gammamurse = arsevals.*dgammamurdrho; 

save murres gammamur gammamurse

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% double check standard errors
clear all

nreps = 1000;

bootgammamur  = zeros(1 ,nreps);


save murbres bootgammamur

for b = 1:nreps
b;
%set seed
seed = 45454 + 10*b;
rand('state', seed);
load  murder_data


tempind = (year<2008);
L_murder = murder(tempind);

tempind = (year>1990);
murder = murder(tempind);
year = year(tempind);


num_coef = 3;

cons = ones(length(murder),1);
[~,~,r,~,stats]= regress(murder, [cons L_murder year ]);
temp = randsample(r,length(r),'true');
[temp,~,r,~,stats]= regress(murder+temp, [cons L_murder year ]);
arvals = temp(2);
temp = sqrt(diag(inv(length(cons))*(r'*r)*inv([cons L_murder year ]'*[cons L_murder year ])));
arsevals = temp(2);

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

T = 7; beta = .95; M= 1;

R = length(arvals);
pxest = zeros(2,1);
gammamur  = zeros(R,1);
dgammamurdrho = zeros(R,1);

for i = 1:R
    pxest(2) = arvals(i);
    [gammamur(i), dgammamurdrho(i)] = gammafunc_se(T,beta,M,pxest);
end

gammamurse = arsevals.*dgammamurdrho; 


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
load murbres

bootgammamur(:,b) = gammamur;
 

save murbres bootgammamur 

end

segammamur = std(bootgammamur); 


save murbres bootgammamur segammamur 